CREATE TABLE [dbo].[DnnProduct_UserRelationships]
(
[UserRelationshipID] [int] NOT NULL IDENTITY(1, 1),
[UserID] [int] NOT NULL,
[RelatedUserID] [int] NOT NULL,
[RelationshipID] [int] NOT NULL,
[Status] [int] NOT NULL,
[CreatedByUserID] [int] NOT NULL,
[CreatedOnDate] [datetime] NOT NULL CONSTRAINT [DF_DnnProduct_UserRelationships_CreatedOnDate] DEFAULT (getdate()),
[LastModifiedByUserID] [int] NOT NULL,
[LastModifiedOnDate] [datetime] NOT NULL CONSTRAINT [DF_DnnProduct_UserRelationships_LastModifiedOnDate] DEFAULT (getdate())
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[DnnProduct_UserRelationships] ADD CONSTRAINT [PK_DnnProduct_UserRelationships] PRIMARY KEY CLUSTERED  ([UserRelationshipID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_DnnProduct_UserRelationships_RelatedUserID] ON [dbo].[DnnProduct_UserRelationships] ([RelatedUserID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_DnnProduct_UserRelationships_UserID] ON [dbo].[DnnProduct_UserRelationships] ([UserID]) ON [PRIMARY]
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_DnnProduct_UserRelationships_UserID_RelatedUserID_RelationshipID] ON [dbo].[DnnProduct_UserRelationships] ([UserID], [RelatedUserID], [RelationshipID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[DnnProduct_UserRelationships] ADD CONSTRAINT [FK_DnnProduct_UserRelationships_DnnProduct_Users_OnRelatedUser] FOREIGN KEY ([RelatedUserID]) REFERENCES [dbo].[DnnProduct_Users] ([UserID])
GO
ALTER TABLE [dbo].[DnnProduct_UserRelationships] ADD CONSTRAINT [FK_DnnProduct_UserRelationships_DnnProduct_Relationships] FOREIGN KEY ([RelationshipID]) REFERENCES [dbo].[DnnProduct_Relationships] ([RelationshipID]) ON DELETE CASCADE
GO
ALTER TABLE [dbo].[DnnProduct_UserRelationships] ADD CONSTRAINT [FK_DnnProduct_UserRelationships_DnnProduct_Users] FOREIGN KEY ([UserID]) REFERENCES [dbo].[DnnProduct_Users] ([UserID])
GO
